<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-main" :isBack="true">
			<block class="text-white" slot="content">提款页面</block>
		</cu-custom>

		<!-- 余额显示 -->
		<view class="cu-card margin-top-xl">
			<view class="cu-item bg-white shadow-blur radius-lg padding">
				<view class="text-center">
					<view class="text-green text-xxl">
						{{amount.amount / 100}}
					</view>
					<view class="text-gray">
						实际可结算金额（元）
					</view>
				</view>
				<view class="padding flex justify-center align-baseline">
					<text>提取金额：</text>
					<input type="number" v-model="tkje" placeholder="1-200元"></input>
				</view>
				<button class="cu-btn bg-green round" @tap="handleConfirm">
					提取
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				tkje: 0,
				amount: {
					openid: "",
					amount: 0
				},
				aclienttq: {
					tqjlid: "",
					amount: "",
					ct: "",
					zt: "R",
					sjje: 0,
					ccbl: 0,
					clientid: this.store.state.client.clientid,
				},
			}
		},
		onLoad: function() {
			this.loadAmount();
		},
		methods: {
			loadAmount: function() {
				return this.api( "/client/info/get").send({
					clientid: this.store.state.client.clientid
				}).then(data => {
					this.amount = data.amount;
				});
			},
			handleConfirm: function() {
				
				if (this.tkje <= 0) {
					this.message.info("请输入提款金额");
					return;
				}
				
				if (this.tkje > 200) {
					this.message.info("单次提款不能超过200");
					return;
				}
				
				if (this.tkje > this.amount.amount) {
					this.message.info("提款金额不能超出余额");
					return;
				}

				this.aclienttq.amount = this.tkje * 100;
				this.api("/client/tq/info").send({
					aclienttq: this.aclienttq
				}).then(data => {
					let targ = JSON.parse(data.aclienttq.tres);
					this.pay.requestMerchantTransfer(targ).then(res => {
						this.message.info("成功");
						uni.navigateBack();
					});
				});
			}
		}
	}
</script>

<style>

</style>